<template>
  <el-dialog
    title="提示"
    :visible.sync="dialogVisible"
    width="80%"
    height="100%"
    :before-close="handleClose"
  >
    <el-table
      :data="tableData"
      style="width: 100%"
      :default-sort="{ prop: 'endTime', order: 'fs' }"
      :row-class-name="tableRowClassName"
    >
      <el-table-column prop="seq" label="序号" sortable :formatter="formatter"></el-table-column>
      <el-table-column prop="systemName" label="所属系统"></el-table-column>
      <el-table-column prop="jgsyName" label="机构名称"></el-table-column>
      <el-table-column prop="fs" label="分数" sortable></el-table-column>
      <el-table-column prop="endTime" label="评估时间" :formatter="formatDate"></el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleClose">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
// 引入js，不需要带后缀
import Sever from '@/api/selfApi'
export default {
  props: {
    dialogVisible: {
      default: true,
      type: Boolean
    },
    level: {
      type: String,
      default: ''
    },
  },
  data() {
    return {
      tableData: []
    }
  },
  watch: {
    dialogVisible(newVal, oldVal) {
      if (newVal) {
        this.initData();
      }
    }
  },
  methods: {
    async initData() {
      let _this = this
      //请求后台返回数据
      try {
        //请求后台接口
        const res = await Sever.analyse.getZgbmListByScoreLevel({
          //请求参数(this.depCode是全局变量)
          dep_code: this.depCode,
          level: this.level
        })
        //取值赋给name和value
        let arr = res.map(item => {
          return {
            systemName: item.SYSTEM_CODE_NAME,
            jgsyName: item.JGSY_NAME,
            fs: item.SUM_FS,
            endTime: item.ETIME
          }
        })
        //赋值给变量
        this.tableData = arr
      } catch (error) {
        console.log(error)
      }
    },

    handleClose() {
      this.$emit('handleClose')
    },
    tableRowClassName({ row, rowIndex }) {
      // 把每一行的索引放进row
      row.rowIndex = rowIndex
    },

    formatter(row, column, cellValue, index) {
      //放回索引值
      return row.rowIndex + 1;
    },
    formatDate(row, column) {
      // 获取单元格数据
      let data = row[column.property]
      if (data == '') {
        return ''
      }
      let dt = new Date(data)
      return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
    }
  }
}
</script>
